package com.cloud.workTest;

import com.cloud.bean.Entity;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {
    public static void main(String[] args) {
        List<Item> itemList = new ArrayList<Item>();
        Item item = new Item();
        item.setId("shuchuanbiao");
        Object originObj = new Object();
        item.setObj(originObj);
        itemList.add(item);
        itemList.stream().map(Item::getObj).forEach(obj -> System.out.println(obj==originObj));

        //测试方法引用
        Entity.getEntityList().forEach(Entity::print);

        //测试map
        Entity.getEntityList().stream()
                .map( entity -> entity.getAttribute())
                .sorted((o1, o2) -> o1.length() - o2.length())
                .forEach(attribute -> System.out.println(attribute));

        Stream.of("one", "two", "three", "four")
                .filter(e -> e.length() > 3)
                .peek(e -> System.out.println("Filtered value: " + e))
                .map(String::toUpperCase)
                .peek(e -> System.out.println("Mapped value: " + e))
                .collect(Collectors.toList());
    }

    public static class Item {
       public String id;
       public Object obj;

        public String getId() {
            return id;
        }

        public Object getObj() {
            return obj;
        }

        public void setId(String id) {
            this.id = id;
        }

        public void setObj(Object obj) {
            this.obj = obj;
        }

        @Override
        public String toString() {
            return "Item{" +
                    "id='" + id + '\'' +
                    ", obj=" + obj +
                    '}';
        }
    }
}
